package router

import (
	"Go_Advanced/bluebell/controller"
	"Go_Advanced/bluebell/logger"
	"Go_Advanced/bluebell/middlewares"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Setup(mode string) *gin.Engine {
	if mode == gin.ReleaseMode {
		gin.SetMode(gin.ReleaseMode) //gin设置成发布模式
	}
	r := gin.New()
	r.Use(logger.GinLogger(), logger.GinRecovery(true))
	v1:=r.Group("/api/v1")
	//注册业务路由
	v1.POST("/signup", controller.SignUpHandler)

	v1.POST("/login", controller.LoginHandler)
	v1.Use(middlewares.JWTAuthMiddleware())//应用认证中间件
	{
		v1.GET("/community",controller.CommunityHandler)
		v1.GET("/community/:id",controller.CommunityDetailHandler)
		v1.POST("/post",controller.CreatePostHandler)
		v1.GET("/post/:id",controller.GETPostDetailHandler)
		v1.GET("/posts",controller.GETPostListHandler)
		//根据时间或者分数获取帖子列表
		v1.GET("/posts2",controller.GETPostListHandler2)
		v1.POST("/vote",controller.PostVoteController)

	}
	r.NoRoute(func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"msg": "404",
		})
	})
	//r.Run(":9090")
	return r
}